package com.ruoyi.sys.energ.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.sys.energ.entity.TbEnergUse;
import com.ruoyi.sys.energ.service.ITbEnergUseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 计量点设备类型和用途管理Controller
 * 
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/energ/use")
public class TbEnergUseController extends BaseController
{
    @Autowired
    private ITbEnergUseService tbEnergUseService;

    /**
     * 查询计量点设备类型和用途管理列表
     */
    @PreAuthorize("@ss.hasPermi('energ:use:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbEnergUse tbEnergUse)
    {
        startPage();
        List<TbEnergUse> list = tbEnergUseService.selectTbEnergUseList(tbEnergUse);
        return getDataTable(list);
    }

    /**
     * 导出计量点设备类型和用途管理列表
     */
    @PreAuthorize("@ss.hasPermi('energ:use:export')")
    @Log(title = "计量点设备类型和用途管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEnergUse tbEnergUse)
    {
        List<TbEnergUse> list = tbEnergUseService.selectTbEnergUseList(tbEnergUse);
        ExcelUtil<TbEnergUse> util = new ExcelUtil<TbEnergUse>(TbEnergUse.class);
        util.exportExcel(response, list, "计量点设备类型和用途管理数据");
    }

    /**
     * 获取计量点设备类型和用途管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('energ:use:query')")
    @GetMapping(value = "/{euId}")
    public AjaxResult getInfo(@PathVariable("euId") Long euId)
    {
        return AjaxResult.success(tbEnergUseService.selectTbEnergUseByEuId(euId));
    }

    /**
     * 新增计量点设备类型和用途管理
     */
    @PreAuthorize("@ss.hasPermi('energ:use:add')")
    @Log(title = "计量点设备类型和用途管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEnergUse tbEnergUse)
    {
        return toAjax(tbEnergUseService.insertTbEnergUse(tbEnergUse));
    }

    /**
     * 修改计量点设备类型和用途管理
     */
    @PreAuthorize("@ss.hasPermi('energ:use:edit')")
    @Log(title = "计量点设备类型和用途管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEnergUse tbEnergUse)
    {
        return toAjax(tbEnergUseService.updateTbEnergUse(tbEnergUse));
    }

    /**
     * 删除计量点设备类型和用途管理
     */
    @PreAuthorize("@ss.hasPermi('energ:use:remove')")
    @Log(title = "计量点设备类型和用途管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{euIds}")
    public AjaxResult remove(@PathVariable Long[] euIds)
    {
        return toAjax(tbEnergUseService.deleteTbEnergUseByEuIds(euIds));
    }
}
